package ru.volgogradetzzz.utils {
	
	import flash.utils.Dictionary;
	
	/**
	 * ...
	 * @author Volgogradetzzz
	 */
	public class Pool {
		
		private static const _FACTORIES:Dictionary = new Dictionary();
		
		public function getObject(classRef:Class):* {
			if (classRef == null) {
				return null;
			}
			
			var factory:Array = _FACTORIES[classRef] as Array;
			if (factory == null || factory.length == 0) {
				return new classRef();
			}else{
				return factory.pop();
			}
		}
		
		public function poolObject(obj:*):void {
			var classRef:Class = obj['constructor'];
			
			if (_FACTORIES[classRef] == null) {
				_FACTORIES[classRef] = new Array();
			}
			
			(_FACTORIES[classRef] as Array).push(obj);
		}
	}
}

internal const SINGLETON_KEY:Object = {};